package com.ruoyi.project.channel.salesmanInfo.service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.ruoyi.project.channel.businessInfo.service.IBusinessInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.channel.salesmanInfo.mapper.SalesmanInfoMapper;
import com.ruoyi.project.channel.salesmanInfo.domain.SalesmanInfo;
import com.ruoyi.project.channel.salesmanInfo.service.ISalesmanInfoService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 业务人员 服务层实现
 * 
 * @author CAIN
 * @date 2024-10-21
 */
@Service
public class SalesmanInfoServiceImpl implements ISalesmanInfoService 
{
	@Autowired
	private SalesmanInfoMapper salesmanInfoMapper;

	@Autowired
	private IBusinessInfoService businessInfoService;

	/**
     * 查询业务人员信息
     * 
     * @param userId 业务人员ID
     * @return 业务人员信息
     */
    @Override
	public SalesmanInfo selectSalesmanInfoById(Long userId)
	{
	    return salesmanInfoMapper.selectSalesmanInfoById(userId);
	}
	
	/**
     * 查询业务人员列表
     * 
     * @param salesmanInfo 业务人员信息
     * @return 业务人员集合
     */
	@Override
	public List<SalesmanInfo> selectSalesmanInfoList(SalesmanInfo salesmanInfo)
	{
	    return salesmanInfoMapper.selectSalesmanInfoList(salesmanInfo);
	}
	
    /**
     * 新增业务人员
     * 
     * @param salesmanInfo 业务人员信息
     * @return 结果
     */
	@Override
	public int insertSalesmanInfo(SalesmanInfo salesmanInfo)
	{
		salesmanInfo.setCreateTime(new Date());
		salesmanInfo.setRate(BigDecimal.ZERO);
		String address = businessInfoService.getAddress();
		salesmanInfo.setAddress(address);
	    return salesmanInfoMapper.insertSalesmanInfo(salesmanInfo);
	}
	
	/**
     * 修改业务人员
     * 
     * @param salesmanInfo 业务人员信息
     * @return 结果
     */
	@Override
	public int updateSalesmanInfo(SalesmanInfo salesmanInfo)
	{
		if(salesmanInfo.getAddress() != null && salesmanInfo.getAddress() .equals("new")){
			String address = businessInfoService.getAddress();
			salesmanInfo.setAddress(address);
		}
	    return salesmanInfoMapper.updateSalesmanInfo(salesmanInfo);
	}

	/**
     * 删除业务人员对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteSalesmanInfoByIds(String ids)
	{
		return salesmanInfoMapper.deleteSalesmanInfoByIds(Convert.toStrArray(ids));
	}
	
}
